﻿/**
  KCAKCAK   CAKCAKC   AK      CA
 AK        KC     CA  AK    AK
CA         KC     CA  AK  KC
CA         KCAKCAKCA  AKCA
CA         KC     CA  AK  KC
 AK        KC     CA  AK    AK
  KCAKCAK  KC     CA  AK      CA

_________________________________________________________________
 China ataca Kamchatka - copyright 2007(c) Ruben Sainz de la Maza
 
	@class: 	CountryStateMachine
	@vertion: 	0.1
	@date:		22/11/07
				
	@language: 	ActionScript 3.0
	@author:	Ruben Sainz de la Maza
	@usage: 

			_objCSM = new CountryStateMachine();
			_objCSM.init();
			_objCSM.freeze(true / false);
			_objCSM.destroy();
		
			//Setear el estado del jugador: ATTACK DEFEND PUT REORGANIZE STANDBY(default)
			_objCSM.state = CountryStateMachine.ATTACK;
			_objCSM.state = CountryStateMachine.DEFEND;
			_objCSM.state = CountryStateMachine.PUT;
			_objCSM.state = CountryStateMachine.REORGANIZE;
			_objCSM.state = CountryStateMachine.STANDBY;
			
			//Devolver el estado actual
			trace(_objCSM.state);
**/

package com.conelmate.cak.board.countries
{
	import com.conelmate.util.Trace;

	
	public class CountryStateMachine extends Trace
	{
		public	static	const	ATTACK			:String = "ATTACK";		//instancia de ataque
		public	static	const	DEFEND			:String = "DEFEND";		//instancia de defensa
		public	static	const	PUT				:String = "PUT";		//instancia de poner ejercitos
		public	static	const	REORGANIZE		:String = "REORGANIZE";	//instancia de reorganizar ejercitos
		public	static	const	STANDBY			:String = "STANDBY";	//instancia de espera (default)

		private			var		_actualState	:String;				//almacena el estado
		
		private			var		_objState		:AbstractCountryState;	//ref a AbstractCountryState


//_________________________________________________________________________________ Constructor
		public function CountryStateMachine()
		{
			_isTrace = false;
			mTrace("#CountryStateMachine# constructor");
			
			//setear el estado por default
			setState(CountryStateMachine.STANDBY);
		}
		
		

//_________________________________________________________________________________ Public Methods

		/**
		 * Inicializa la clase
		 */
		public function init():void
		{
			_objState.init(); 
		}
		

		/**
		 * Destruye las instancias
		 */
		public function destroy():void
		{ 
			_objState.destroy(); 
		}
		

		/**
		 * Congela / descongela los eventos de la clase
		 * @param   freeze 
		 */	
		public function freeze(p:Boolean):void
		{
			_objState.freeze(p); 
		}



//_________________________________________________________________________________ Private Methods

		/**
		 * Cambia el estado actual del jugador
		 * @param   stateDesc: ATTACK DEFEND PUT REORGANIZE STANDBY
		 */		
		private function setState(stateDesc:String):void
		{
			_actualState = stateDesc;
			mTrace("#CountryStateMachine# setState " + _actualState);
			
			switch(_actualState)
			{
				//diferentes estados:
				case ATTACK:		_objState = new StateAttack();		break;
				case DEFEND:		_objState = new StateDefend();		break;
				case PUT:			_objState = new StatePut();			break;
				case REORGANIZE:	_objState = new StateReorganize();	break;
				case STANDBY:		_objState = new StateStandby();		break;
				default:			_objState = null;
			}			
		}
		


//_________________________________________________________________________________ GETTERS

		public function get state() :String	{ return _actualState; }
		
//_________________________________________________________________________________ SETTERS			

		public function set state	(p:String)	{ setState(p); }
		
		
	}
}